bitkeeper revision 1.1108.45.1 (410c1a5ciBWG2JsmEjIJbaQp8U-jtg)
authoriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Sat, 31 Jul 2004 22:17:00 +0000 (22:17 +0000)
committeriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Sat, 31 Jul 2004 22:17:00 +0000 (22:17 +0000)
Avoid use of /sbin/sfdisk in determining blk dev size.

linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/common.h
linux-2.4.26-xen-sparse/arch/xen/drivers/blkif/backend/vbd.c
tools/python/xen/xend/XendDomainInfo.py
tools/python/xen/xend/server/blkif.py

index a9f2b87844aee74fa0fb12cac7412860d601a082..c1842033ab8b5c08694e58fe5dc1071bc00140c5 100644 (file)
@@ -26,6 +26,9 @@
 #define DPRINTK(_f, _a...) ((void)0)
 #endif
 
+#define PRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
+                           __FILE__ , __LINE__ , ## _a )
+
 typedef struct blkif_st {
     /* Unique identifier for this interface. */
     domid_t          domid;
index 8e5d568960359d53efa38309e3ed304ffd55950e..bbb094a4d432c142eeecf62d1b16164780a80024 100644 (file)
@@ -18,7 +18,7 @@ void vbd_create(blkif_be_vbd_create_t *create)
     blkif = blkif_find_by_handle(create->domid, create->blkif_handle);
     if ( unlikely(blkif == NULL) )
     {
-        DPRINTK("vbd_create attempted for non-existent blkif (%u,%u)\n", 
+        PRINTK("vbd_create attempted for non-existent blkif (%u,%u)\n", 
                 create->domid, create->blkif_handle); 
         create->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND;
         return;
@@ -41,7 +41,7 @@ void vbd_create(blkif_be_vbd_create_t *create)
         }
         else
         {
-            DPRINTK("vbd_create attempted for already existing vbd\n");
+            PRINTK("vbd_create attempted for already existing vbd\n");
             create->status = BLKIF_BE_STATUS_VBD_EXISTS;
             goto out;
         }
@@ -49,7 +49,7 @@ void vbd_create(blkif_be_vbd_create_t *create)
 
     if ( unlikely((vbd = kmalloc(sizeof(vbd_t), GFP_KERNEL)) == NULL) )
     {
-        DPRINTK("vbd_create: out of memory\n");
+        PRINTK("vbd_create: out of memory\n");
         create->status = BLKIF_BE_STATUS_OUT_OF_MEMORY;
         goto out;
     }
@@ -85,7 +85,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow)
     blkif = blkif_find_by_handle(grow->domid, grow->blkif_handle);
     if ( unlikely(blkif == NULL) )
     {
-        DPRINTK("vbd_grow attempted for non-existent blkif (%u,%u)\n", 
+        PRINTK("vbd_grow attempted for non-existent blkif (%u,%u)\n", 
                 grow->domid, grow->blkif_handle); 
         grow->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND;
         return;
@@ -107,7 +107,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow)
 
     if ( unlikely(vbd == NULL) || unlikely(vbd->vdevice != vdevice) )
     {
-        DPRINTK("vbd_grow: attempted to append extent to non-existent VBD.\n");
+        PRINTK("vbd_grow: attempted to append extent to non-existent VBD.\n");
         grow->status = BLKIF_BE_STATUS_VBD_NOT_FOUND;
         goto out;
     } 
@@ -115,7 +115,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow)
     if ( unlikely((x = kmalloc(sizeof(blkif_extent_le_t), 
                                GFP_KERNEL)) == NULL) )
     {
-        DPRINTK("vbd_grow: out of memory\n");
+        PRINTK("vbd_grow: out of memory\n");
         grow->status = BLKIF_BE_STATUS_OUT_OF_MEMORY;
         goto out;
     }
@@ -127,7 +127,7 @@ void vbd_grow(blkif_be_vbd_grow_t *grow)
     
     if( !blk_size[MAJOR(x->extent.device)] )
     {
-        DPRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device);
+        PRINTK("vbd_grow: device %08x doesn't exist.\n", x->extent.device);
        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
        goto out;
     }
@@ -135,9 +135,16 @@ void vbd_grow(blkif_be_vbd_grow_t *grow)
     /* convert blocks (1KB) to sectors */
     sz = blk_size[MAJOR(x->extent.device)][MINOR(x->extent.device)] * 2;    
     
+    if ( sz == 0 )
+    {
+        PRINTK("vbd_grow: device %08x zero size!\n", x->extent.device);
+       grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
+       goto out;
+    }
+
     if ( x->extent.sector_start > 0 )
     {
-        DPRINTK("vbd_grow: device %08x start not zero!\n", x->extent.device);
+        PRINTK("vbd_grow: device %08x start not zero!\n", x->extent.device);
        grow->status = BLKIF_BE_STATUS_EXTENT_NOT_FOUND;
        goto out;
     }
@@ -237,7 +244,7 @@ void vbd_destroy(blkif_be_vbd_destroy_t *destroy)
     blkif = blkif_find_by_handle(destroy->domid, destroy->blkif_handle);
     if ( unlikely(blkif == NULL) )
     {
-        DPRINTK("vbd_destroy attempted for non-existent blkif (%u,%u)\n", 
+        PRINTK("vbd_destroy attempted for non-existent blkif (%u,%u)\n", 
                 destroy->domid, destroy->blkif_handle); 
         destroy->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND;
         return;
index e7128c06c0d092eb45ff552171711dd7cd754059..45da2c250fcfec6cf88c2de75e517a6bffe553da 100644 (file)
@@ -83,9 +83,18 @@ def blkdev_name_to_number(name):
     'hda') and return the device number used by the OS. """
 
     if not re.match( '^/dev/', name ):
-        name = '/dev/' + name
+        n = '/dev/' + name
         
-    return os.stat(name).st_rdev
+    try:
+       return os.stat(n).st_rdev
+    except:
+       pass
+
+    # see if this is a hex device number
+    if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
+       return string.atoi(name,16)
+       
+    return None
 
 def lookup_raw_partn(name):
     """Take the given block-device name (e.g., '/dev/sda1', 'hda')
@@ -97,27 +106,14 @@ def lookup_raw_partn(name):
         type:         'Disk' or identifying name for partition type
     """
 
-    p = name
-
-    if not re.match( '^/dev/', name ):
-        p = '/dev/' + name
-               
-    fd = os.popen( '/sbin/sfdisk -s ' + p + ' 2>/dev/null' )
-    line = _readline(fd)
-    if line:
-       return [ { 'device' : blkdev_name_to_number(p),
+    n = blkdev_name_to_number(name)
+    if n:
+       return [ { 'device' : n,
                   'start_sector' : long(0),
                   'nr_sectors' : long(1L<<63),
                   'type' : 'Disk' } ]
     else:
-       # see if this is a hex device number
-       if re.match( '^(0x)?[0-9a-fA-F]+$', name ):
-           return [ { 'device' : string.atoi(name,16),
-                  'start_sector' : long(0),
-                  'nr_sectors' : long(1L<<63),
-                  'type' : 'Disk' } ]
-       
-    return None
+       return None
 
 def lookup_disk_uname(uname):
     """Lookup a list of segments for a physical device.
index 5c62a81e0e521bbfef75a9f5ac7bf8291e021f44..a51754bad31318589629601ada53a6655dd716ce 100755 (executable)
@@ -194,6 +194,12 @@ class BlkifControllerFactory(controller.ControllerFactory):
         """
         val = unpackMsg('blkif_be_vbd_grow_t', msg)
         # Check status?
+       status = val['status']
+       if status != BLKIF_BE_STATUS_OKAY:
+            log.debug("Error: Adding extent to vbd failed! (device %x)",
+                     val['extent.device'])
+            # what to do here to abort????
+
         if self.attached:
             if d:
                 d.callback(dev)